/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.ipti.br.tag.entity;

import org.ipti.br.tag.entity.enums.CampaignType;
import java.util.Calendar;
import javax.persistence.*;
import org.ipti.br.tag.util.EncryptionUtil;

/**
 *
 * @author root
 */
@Entity
public class Campaign extends AbstractEntity{
    
    @Temporal(TemporalType.DATE)
    @Column(nullable=false)
    private Calendar initialDate;
    
    @Temporal(TemporalType.DATE)
    @Column(nullable=false)
    private Calendar terminalDate;
    
    @Column(nullable=false)
    private String name;
    
    @Enumerated(EnumType.ORDINAL)
    @Column(nullable =false)
    private CampaignType type;
    
    @Override
    public void generateHash(){
        if ( getId() == null){
            String hash =""
                    + this.getName()
                    + this.getInitialDate()
                    + this.getTerminalDate()
                    + this.getType(); 
            this.setId( Long.valueOf( EncryptionUtil.encrypt(hash).hashCode()));
        }
    }

    public Calendar getInitialDate() {
        return initialDate;
    }

    public void setInitialDate(Calendar initialDate) {
        this.initialDate = initialDate;
    }

    public Calendar getTerminalDate() {
        return terminalDate;
    }

    public void setTerminalDate(Calendar terminalDate) {
        this.terminalDate = terminalDate;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public CampaignType getType() {
        return type;
    }

    public void setType(CampaignType type) {
        this.type = type;
    }
}
